<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 16:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Flight" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>航班管理系统</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        table tr:nth-child(even) {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>航班列表</h2>
<!-- 查询表单 -->
<form action="index.jsp" method="get">
    <select name="conditionColumn">
        <option value="fid">航班ID</option>
        <option value="starttime">起飞时间</option>
        <option value="endtime">到达时间</option>
        <option value="takeoffstation">起飞站</option>
        <option value="arrivalstation">到达站</option>
        <option value="boardingtime">登机时间</option>
    </select>
    <input type="text" name="conditionValue" placeholder="输入查询值">
    <input type="submit" value="查询">
</form>

<!-- 显示航班列表 -->
<table>
    <thead>
    <tr>
        <th>航班ID</th>
        <th>起飞时间</th>
        <th>到达时间</th>
        <th>起飞站</th>
        <th>到达站</th>
        <th>登机时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        DB_Flight dbFlight = new DB_Flight();
        String conditionColumn = request.getParameter("conditionColumn");
        if (conditionColumn == null) {
            conditionColumn = "";
        }
        String conditionValue = request.getParameter("conditionValue");
        if (conditionValue == null) {
            conditionValue = "";
        }
        List<String> returnList = new ArrayList<>();
        dbFlight.find(conditionColumn, conditionValue, returnList);
        for (int i = 0; i < returnList.size(); i += 6) {
    %>
    <tr>
        <td><%= returnList.get(i) %></td>
        <td><%= returnList.get(i + 1) %></td>
        <td><%= returnList.get(i + 2) %></td>
        <td><%= returnList.get(i + 3) %></td>
        <td><%= returnList.get(i + 4) %></td>
        <td><%= returnList.get(i + 5) %></td>
        <td>
            <a href="editFlight.jsp?fid=<%= returnList.get(i) %>">编辑</a>
            <a href="deleteFlight.jsp?fid=<%= returnList.get(i) %>">删除</a>
        </td>
    </tr>
    <% } %>
    </tbody>
</table>

<!-- 添加航班表单 -->
<h2>添加航班</h2>
<form action="addFlight.jsp" method="post">
    <label for="starttimeYear">起飞时间 - 年:</label>
    <select id="starttimeYear" name="starttimeYear">
        <% for (int year = 2024; year <= 2030; year++) { %>
        <option value="<%= year %>"><%= year %></option>
        <% } %>
    </select>
    <select id="starttimeMonth" name="starttimeMonth">
        <% for (int month = 1; month <= 12; month++) { %>
        <option value="<%= String.format("%02d", month) %>"><%= String.format("%02d", month) %></option>
        <% } %>
    </select>
    <select id="starttimeDay" name="starttimeDay">
        <% for (int day = 1; day <= 31; day++) { %>
        <option value="<%= String.format("%02d", day) %>"><%= String.format("%02d", day) %></option>
        <% } %>
    </select>
    <select id="starttimeHour" name="starttimeHour">
        <% for (int hour = 0; hour < 24; hour++) { %>
        <option value="<%= String.format("%02d", hour) %>"><%= String.format("%02d", hour) %></option>
        <% } %>
    </select>
    <select id="starttimeMinute" name="starttimeMinute">
        <% for (int minute = 0; minute < 60; minute++) { %>
        <option value="<%= String.format("%02d", minute) %>"><%= String.format("%02d", minute) %></option>
        <% } %>
    </select>
    <select id="starttimeSecond" name="starttimeSecond">
        <% for (int second = 0; second < 60; second++) { %>
        <option value="<%= String.format("%02d", second) %>"><%= String.format("%02d", second) %></option>
        <% } %>
    </select><br>

    <label for="endtimeYear">到达时间 - 年:</label>
    <select id="endtimeYear" name="endtimeYear">
        <% for (int year = 2024; year <= 2030; year++) { %>
        <option value="<%= year %>"><%= year %></option>
        <% } %>
    </select>
    <select id="endtimeMonth" name="endtimeMonth">
        <% for (int month = 1; month <= 12; month++) { %>
        <option value="<%= String.format("%02d", month) %>"><%= String.format("%02d", month) %></option>
        <% } %>
    </select>
    <select id="endtimeDay" name="endtimeDay">
        <% for (int day = 1; day <= 31; day++) { %>
        <option value="<%= String.format("%02d", day) %>"><%= String.format("%02d", day) %></option>
        <% } %>
    </select>
    <select id="endtimeHour" name="endtimeHour">
        <% for (int hour = 0; hour < 24; hour++) { %>
        <option value="<%= String.format("%02d", hour) %>"><%= String.format("%02d", hour) %></option>
        <% } %>
    </select>
    <select id="endtimeMinute" name="endtimeMinute">
        <% for (int minute = 0; minute < 60; minute++) { %>
        <option value="<%= String.format("%02d", minute) %>"><%= String.format("%02d", minute) %></option>
        <% } %>
    </select>
    <select id="endtimeSecond" name="endtimeSecond">
        <% for (int second = 0; second < 60; second++) { %>
        <option value="<%= String.format("%02d", second) %>"><%= String.format("%02d", second) %></option>
        <% } %>
    </select><br>

    <label for="takeoffstation">起飞站:</label>
    <input type="text" id="takeoffstation" name="takeoffstation" required><br>
    <label for="arrivalstation">到达站:</label>
    <input type="text" id="arrivalstation" name="arrivalstation" required><br>

    <label for="boardingtimeYear">登机时间 - 年:</label>
    <select id="boardingtimeYear" name="boardingtimeYear">
        <% for (int year = 2024; year <= 2030; year++) { %>
        <option value="<%= year %>"><%= year %></option>
        <% } %>
    </select>
    <select id="boardingtimeMonth" name="boardingtimeMonth">
        <% for (int month = 1; month <= 12; month++) { %>
        <option value="<%= String.format("%02d", month) %>"><%= String.format("%02d", month) %></option>
        <% } %>
    </select>
    <select id="boardingtimeDay" name="boardingtimeDay">
        <% for (int day = 1; day <= 31; day++) { %>
        <option value="<%= String.format("%02d", day) %>"><%= String.format("%02d", day) %></option>
        <% } %>
    </select>
    <select id="boardingtimeHour" name="boardingtimeHour">
        <% for (int hour = 0; hour < 24; hour++) { %>
        <option value="<%= String.format("%02d", hour) %>"><%= String.format("%02d", hour) %></option>
        <% } %>
    </select>
    <select id="boardingtimeMinute" name="boardingtimeMinute">
        <% for (int minute = 0; minute < 60; minute++) { %>
        <option value="<%= String.format("%02d", minute) %>"><%= String.format("%02d", minute) %></option>
        <% } %>
    </select>
    <select id="boardingtimeSecond" name="boardingtimeSecond">
        <% for (int second = 0; second < 60; second++) { %>
        <option value="<%= String.format("%02d", second) %>"><%= String.format("%02d", second) %></option>
        <% } %>
    </select><br>

    <input type="submit" value="添加航班">
</form>
</body>
</html>
